package com.mapexample.utilities;
import android.content.Context;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class Utility
{

	public Utility()
	{

	}

	/**
	 * Checks if App is installed or not.
	 * 
	 * @param uri the uri
	 * @return true, if successful
	 * @detail checks whether app is present or not in device
	 */
	public static boolean isPackageAvailable(Context mCxt, String uri)
	{
		PackageManager pm = mCxt.getPackageManager();
		boolean app_installed = false;
		try
		{
			pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
			app_installed = true;
		}
		catch (PackageManager.NameNotFoundException e)
		{
			app_installed = false;
		}
		return app_installed;
	}

	/**
	 * Checks if device is online.
	 * 
	 * @param context the context
	 * @return true, if is online
	 */
	public static boolean isOnline(Context context)
	{
		ConnectivityManager cm = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo ni = cm.getActiveNetworkInfo();
		return (ni != null && ni.isAvailable() && ni.isConnected());
	}

}
